<!DOCTYPE html>
<html>
    {% load static %}
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">

		<title>绑定手机</title>

		<link href="{% static 'assets/css/admin.css' %}" rel="stylesheet" type="text/css">
		<link href="{% static 'assets/css/amazeui.css' %}" rel="stylesheet" type="text/css">

		<link href="{% static 'css/personal.css' %}" rel="stylesheet" type="text/css">
		<link href="{% static 'css/stepstyle.css' %}" rel="stylesheet" type="text/css">

		<script type="text/javascript" src="{% static 'js/jquery-1.7.2.min.js' %}"></script>
		<script src="{% static 'assets/js/amazeui.js' %}"></script>
        <script type="text/javascript">
        $(function() {

            //短信验证码
            //1. 找标签:btn1
            //2. 定时器完成: 显示时间变化!!!
            //setInterval(函数, 时间)
            //3.难点: 定时器中函数,不断减1, 见到<0终止!!!!
            var btn1 = $('#sendsms');
            var count = 60; // 倒计时数量 一般为60秒!
            var timer = null; //定时器
            var phone={{ phone }};
            //事件
            btn1.click(function () {
                if (phone == '') {
                    alert('请绑定电话号码');
                    return false;
                }
                if (!(/^1[3456789]\d{9}$/.test(phone))) {
                    alert("手机号码有误，请重填");
                    return false;
                }
                //Ajax发送短s信
                $.ajax({
                    type: 'get',
                    url: '/home/sms_send/',
                    data: 'phone=' + phone,
                    success: function (msg) {
                        console.log("成功返回结果:" + msg);
                        obj = eval("(" + msg + ")");
                        if (obj.Message == "OK") {
                            {#$("#msg").html("发送成功")#}
                            alert('短信验证码发送成功')
                        } else {
                            {#$("#msg").html("发送失败")#}
                            alert("短信验证码发送失败")
                        }
                    },
                    error: function (resp) {
                        console.log(resp.status);
                        alert('连接后台失败')
                    }
                });
                //end 发送短信
                alert('短信验证码已发送');

                //禁用
                $(this).attr("disabled", 'true');
                var _this = $(this);
                //定时器实现时间每次减少1
                timer = setInterval(function () {
                    count--;
                    console.log("剩余时间:" + count);
                    if (count >= 0) {
                        //this表示对象!!!! 表示定时器!!!!
                        //this.innerHTML="时间剩余"+ count+"秒";
                        _this.html(count + "秒后重发")
                    } else {
                        _this.disabled = false;
                        clearInterval(timer);
                        _this.html("重新发送");
                        count = 5;
                        $('#sendsms').removeAttr("disabled")
                    }
                }, 1000);
            });
            //短信验证end
            //短信验证

        })
    </script>
        <script type="text/javascript">
            $(function(){
                var phone={{ phone }}
                $("#code").change(function () {
                    //验证ajax
                    if(phone==''){
                        alert("请绑定手机号码")
                    }
                    {#phone = $('#phone').val();#}
                    code = $('#code').val();
                    $.ajax({
                        type: "get",
                        url: "/home/sms_check/",
                        data: "phone=" + phone + "&code=" + code,
                        success: function (result) {
                            console.log("Data Saved: " + result);
                            //已经为json
                            if (result.code == "200") {
                                alert('手机验证码验证成功');
                            } else {
                                {#$('#msg').html('手机验证码输入错误')#}
                                alert('验证码输入错误或您还未输入验证码,请您检查')
                            }
                            },
                        error: function (res) {
                            //状态码
                            console.log(res.status)
                        }
                    });
                })
            })

        </script>
        <script type="text/javascript">
        $(function() {

            //短信验证码
            //1. 找标签:btn1
            //2. 定时器完成: 显示时间变化!!!
            //setInterval(函数, 时间)
            //3.难点: 定时器中函数,不断减1, 见到<0终止!!!!
            var btn1 = $('#sendsmss');
            var count = 60; // 倒计时数量 一般为60秒!
            var timer = null; //定时器
            var phone1=$('#user_new_phone').val();
            //事件
            btn1.click(function () {
                if (phone1=='') {
                    alert('请输入电话号码');
                    return false;
                }
                if (!(/^1[3456789]\d{9}$/.test(phone))) {
                    alert("手机号码有误，请重填");
                    return false;
                }
                //Ajax发送短s信
                $.ajax({
                    type: 'get',
                    url: '/home/sms_send/',
                    data: 'phone=' + phone,
                    success: function (msg) {
                        console.log("成功返回结果:" + msg);
                        obj = eval("(" + msg + ")");
                        if (obj.Message == "OK") {
                            {#$("#msg").html("发送成功")#}
                            alert('短信验证码发送成功')
                        } else {
                            {#$("#msg").html("发送失败")#}
                            alert("短信验证码发送失败")
                        }
                    },
                    error: function (resp) {
                        console.log(resp.status);
                        alert('连接后台失败')
                    }
                });
                //end 发送短信
                alert('短信验证码已发送');

                //禁用
                $(this).attr("disabled", 'true');
                var _this = $(this);
                //定时器实现时间每次减少1
                timer = setInterval(function () {
                    count--;
                    console.log("剩余时间:" + count);
                    if (count >= 0) {
                        //this表示对象!!!! 表示定时器!!!!
                        //this.innerHTML="时间剩余"+ count+"秒";
                        _this.html(count + "秒后重发")
                    } else {
                        _this.disabled = false;
                        clearInterval(timer);
                        _this.html("重新发送");
                        count = 5;
                        $('#sendsms').removeAttr("disabled")
                    }
                }, 1000);
            });
            //短信验证end
            //短信验证

        })
    </script>
        <script type="text/javascript">
            $(function(){
                $("#code").change(function () {
                    //验证ajax
                    {#phone = $('#phone').val();#}
                    code = $('#codea').val();
                    $.ajax({
                        type: "get",
                        url: "/home/sms_check/",
                        data: "phone=" + phone + "&code=" + code,
                        success: function (result) {
                            console.log("Data Saved: " + result);
                            //已经为json
                            if (result.code == "200") {
                                alert('手机验证码验证成功');
                            } else {
                                {#$('#msg').html('手机验证码输入错误')#}
                                alert('验证码输入错误或您还未输入验证码,请您检查')
                            }
                            },
                        error: function (res) {
                            //状态码
                            console.log(res.status)
                        }
                    });
                })
            })

        </script>

	</head>
	<body>
        {% include 'person/top.html' %}
		<div class="center">
			<div class="col-main">
				<div class="main-wrap">

					<div class="am-cf am-padding">
						<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">绑定手机</strong> / <small>Bind&nbsp;Phone</small></div>
					</div>
					<hr/>
					<!--进度条-->
					<div class="m-progress">
						<div class="m-progress-list">
							<span class="step-1 step">
                                <em class="u-progress-stage-bg"></em>
                                <i class="u-stage-icon-inner">1<em class="bg"></em></i>
                                <p class="stage-name">绑定手机</p>
                            </span>
							<span class="step-2 step">
                                <em class="u-progress-stage-bg"></em>
                                <i class="u-stage-icon-inner">2<em class="bg"></em></i>
                                <p class="stage-name">完成</p>
                            </span>
							<span class="u-progress-placeholder"></span>
						</div>
						<div class="u-progress-bar total-steps-2">
							<div class="u-progress-bar-inner"></div>
						</div>
					</div>
					<form class="am-form am-form-horizontal" action="{% url 'myself:myself_bindphone' %}" method="post">
						<div class="am-form-group bind">
							<label for="user-phone" class="am-form-label">验证手机</label>
							<div class="am-form-content">
                                {% if user.is_authenticated %}
                                    {% if phone is None %}
                                        <span id="user-phone">请您完善资料！</span>
                                    {% else %}
                                        <span id="user-phone">{{ phone }}</span>
                                    {% endif %}
                                {% else %}
                                    <span id="user-phone">请您登录!!!</span>
                                {% endif %}
							</div>
						</div>
						<div class="am-form-group code">
                            <label for="user-code" class="am-form-label">验证码</label>
                            <div class="am-form-content">
                                <input type="tel" id="code" placeholder="短信验证码">
                            </div>
                            <a class="btn" href="#" id="sendsms">
								<div class="am-btn am-btn-danger">验证码</div>
                            </a>
                        </div>
{#                        ///////////////////////////////////////////////////////////////////////////////////////////#}
                        <div class="am-form-group">
                            <label for="user-new-phone" class="am-form-label">验证手机</label>
                            <div class="am-form-content">
                                <input type="tel" id="user_new_phone" placeholder="绑定新手机号" name="newphone">
                            </div>
                        </div>
                        <div class="am-form-group code">
                            <label for="user-new-code" class="am-form-label">验证码</label>
                            <div class="am-form-content">
                                <input type="tel" id="codea" placeholder="短信验证码" name="nccode">
                            </div>
                            <a class="btn" href="#" id="sendsmss">
                                <div class="am-btn am-btn-danger">验证码</div>
                            </a>
						</div>
						<div class="info-btn">
							<div class="am-btn am-btn-danger"><input type="submit" value="保存修改"></div>
						</div>
                    <span style="color: skyblue;">{{ erop }}</span>
					</form>

				</div>
				<!--底部-->
				<div class="footer">
					<div class="footer-hd">
						<p>
							<a href="#">恒望科技</a>
							<b>|</b>
							<a href="#">商城首页</a>
							<b>|</b>
							<a href="#">支付宝</a>
							<b>|</b>
							<a href="#">物流</a>
						</p>
					</div>
					<div class="footer-bd">
						<p>
							<a href="#">关于恒望</a>
							<a href="#">合作伙伴</a>
							<a href="#">联系我们</a>
							<a href="#">网站地图</a>
							<em>© 2015-2025 Hengwang.com 版权所有</em>
						</p>
					</div>
				</div>
			</div>

			<aside class="menu">
				<ul>
					<li class="person active">
						<a href="{% url 'myself:index' %}">个人中心</a>
					</li>
					<li class="person">
						<a href="#">个人资料</a>
						<ul>
							<li> <a href="{% url 'myself:myself_information' %}">个人信息</a></li>
							<li> <a href="{% url 'myself:myself_safety' %}">安全设置</a></li>
							<li> <a href="{% url 'myself:address' %}">收货地址</a></li>
						</ul>
					</li>
					<li class="person">
						<a href="#">我的交易</a>
						<ul>
							<li><a href="{% url 'myself:myself_order' %}">订单管理</a></li>
							<li> <a href="{% url 'myself:myself_change' %}">退款售后</a></li>
						</ul>
					</li>
					<li class="person">
						<a href="#">我的资产</a>
						<ul>
							<li> <a href="{% url 'myself:myself_coupon' %}">优惠券 </a></li>
							<li> <a href="{% url 'myself:myself_bonus' %}">红包</a></li>
							<li> <a href="{% url 'myself:myself_bill' %}">账单明细</a></li>
						</ul>
					</li>

					<li class="person">
						<a href="#">我的小窝</a>
						<ul>
							<li> <a href="{% url 'myself:myself_collection' %}">收藏</a></li>
							<li> <a href="{% url 'myself:myself_foot' %}">足迹</a></li>
							<li> <a href="{% url 'myself:myself_comment' %}">评价</a></li>
							<li> <a href="{% url 'myself:myself_news' %}">消息</a></li>
						</ul>
					</li>

				</ul>

			</aside>
		</div>

	</body>

</html>